export function  requestIntercept(){
	uni.addInterceptor('request', {
	  invoke(args) {
	    // request 触发前拼接 url 
		uni.showLoading({
			title:"正在加载",
			mask:true
		})
		
	  },
	  success(args) {
		  
	  }, 
	  fail(err) {
	  
	  }, 
	  complete(res) {
	   uni.hideLoading()
	  }
	})
}
export function routerIntercept(){
	let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"];
		list.forEach(item => { //用遍历的方式分别为,uni.navigateTo,uni.redirectTo,uni.reLaunch,uni.switchTab这4个路由方法添加拦截器
			uni.addInterceptor(item, {
				invoke(e) { // 调用前拦截
					//获取用户的token
					const token = uni.getStorageSync('user');
					const admin = uni.getStorageSync('admin'),
					//const admin = uni.getStorageSync("admin")
						//获取要跳转的页面路径（url去掉"?"和"?"后的参数）
						url = e.url.split('?')[0];
					let notNeed = ["/package_admin/adminLogin/adminLogin","/pages/alarm/alarm","/pages/index/index"].includes(url)
					// 如果在whiteList里面就不需要登录
					if (notNeed) {
						return e
					} else { 
						//需要登录
						if (token == '' && admin == '') {
							uni.navigateTo({
								url: "/pages/index/index"
							})
							uni.showToast({
								title: '请先登录',
								icon: 'none',
								duration:2000
							})
							return false
						}else{
							return e
						}
					}
					
				},
				fail(err) { // 失败回调拦截 
					console.log(err);
					if (Debug) {
						console.log(err);
						uni.showModal({
							content: JSON.stringify(err),
							showCancel: false
						});
					}
				}
			})
		})
	}